package com.yaosheng.thread.lock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by yaosheng on 2021/6/30.
 */
public class ReentrantLock2 extends Thread{

    public static void main(String[] args) {
        final Lock lock = new ReentrantLock ();

        Thread t1 = new Thread ( () -> {
            try{
                lock.lock ();
                System.out.println ("t1 start");
                TimeUnit.SECONDS.sleep (Integer.MAX_VALUE);
                System.out.println ("t1 end");
            }catch (InterruptedException e){
                e.printStackTrace ();
            }finally {
                lock.unlock ();
            }
        });
        t1.start ();
    }
}
